package core.process.pack;

import core.rb.PB;
import gui.processor.Processor;
import gui.utils.ProgBar;
import java.util.concurrent.CountDownLatch;
import java.util.ArrayList;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class QualPack extends Thread{
    private final CountDownLatch stopLatch;
    protected PB pIn;
    protected ArrayList <Integer> [] pOut;
    private Processor p;
    public QualPack(Processor gp, CountDownLatch sl, PB pIn){
        super();
        this.p = gp;
        this.pIn = pIn;
        this.stopLatch = sl;
        this.start();
    }
    public void run(){
        pOut = getQScores();
        stopLatch.countDown();
    }

    public ArrayList <Integer> [] getPOut(){return pOut;}

    private ArrayList <Integer> [] getQScores() {
        String ref = pIn.getRef().getDNA();
        ArrayList <Integer> [] sQuals = new ArrayList[ref.length()];
        ArrayList <Integer> quals;
        int qual;
        if(p!=null){
            p.dPrg(ProgBar.START, ref.length());
            for(int s=0; s<ref.length(); s++){
                quals = new ArrayList();
                for(int z=0; z<pIn.getSize(); z++){
                    qual = pIn.getMisQs(z, s);
                    if(qual!=-1){quals.add(qual);}
                }
                sQuals[s] = quals;
                p.dPrg(ProgBar.UPDATE, s);
            }
            p.dPrg(ProgBar.END, 0);
        }
        for(int s=0; s<ref.length(); s++){
            quals = new ArrayList();
            for(int z=0; z<pIn.getSize(); z++){
                qual = pIn.getMisQs(z, s);
                if(qual!=-1){quals.add(qual);}
            }
            sQuals[s] = quals;
        }
        return sQuals;
    }
}